package logic

import (
	"context"
	"goods-login/goods/goods"
	"goods-login/goods/internal/svc"
	"goods-login/model/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodListLogic {
	return &GoodListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodListLogic) GoodList(in *goods.GoodListRequest) (*goods.GoodListResponse, error) {
	// todo: add your logic here and delete this line
	var data []*goods.GoodList
	mysql.DB.Model(goods.GoodList{}).Table("goods").Select(
		"users.id as user_id",
		"goods.`name`",
		"goods.price",
		"goods.num",
		"goods.shop_name",
		" goods.created_at").Joins("LEFT JOIN users ON goods.user_id=users.id").Find(&data)
	return &goods.GoodListResponse{
		List: data,
	}, nil
}
